#include "image.h"
int nextPow2(int x){
	int hi = 0;
	for (int i = 31; i >= 0; i--){
		if ((1 << i) & i){
			if (hi){
				return h1 << 1;
			}
			else{
				hi = 1 << i;
			}
		}
	}
	return 0;
}
Image::Image(char *filename, enum Format type){
	switch (type){
		BITMAP:
			loadBitmap(filename);
		break;
		PNG:
			loadPng(filename);
		break;
		JPEG:
			loadJpeg(filename);
		break;
	}
}
Image::Image(int width, int height, int colour){
	createImage(width, height);
	colourImage(colour);
}
void Image::colourImage(int colour){
	vector<vector<Texture*>*>::iterator it = textures->begin();
	for (;it != textures->end(); it++){
		vector<Texture*>::iterator row = it->begin();
		for (;row != it->end(); row++){
			row->colour(colour);
		}
	}
}

void Image::createImage(int width, int height){
	this->width = width;
	this->height = height;
	int h = height;
	textures = new vector<vector<Texture*>*>();
	while (h > 512){
		int w = width;
		vector<Texture*> *row = new vector<Texture*>();
		while (w > 512){
			row->push_back(new Texture(512, 512));
			w -= 512; 
		}
		row->push_back(new Texture(w, 512));
		h -= 512;
		textures->push_back(row);
	}
	int w = width;
	vector<Texture*> *row = new vector<Texture*>();
	while (w > 512){
		row->push_back(new Texture(512, h));
	}
	row->push_back(new Texture(w, h));
	textures->push_back(row);
}
Image::~Image(){
	for (vector<vector<texture*>*>::iterator it = textures->begin(); it != textures->end(); it++){
		for (vector<texyure*>::iterator row = *it->begin(); row != *it->end(); row++){
			delete *row;
		}
	}
	delete menuItems;
}

void Image::loadBitmap(char *filename){
	fstream stream(filename, fstream::binary|fstream::in);
	if (!stream.is_open()) return;
	BitmapFileHeader bfh;
	stream.((char*)&bfh, 
	
}

void Image::loadPng(char *filename){
	
}